home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / TGE129C.ZIP / SIMPLE.CPP < prev    next >
C/C++ Source or Header  |  1993-08-20  |  3KB  |  121 lines

  1. //*************************************************************************
  2. //* Program:  SIMPLE.CPP                          *
  3. //*                                      *
  4. //* Purpose:  This program does almost nothing when it is run; it is not  *
  5. //*          intended to be run, but as an example in source code form   *
  6. //*          of how to interface to TGE's various features.  The setup() *
  7. //*          function illustrates how to initialize these features, and  *
  8. //*          demo() illustrates briefly how to use them.          *
  9. //*************************************************************************
  10.  
  11. #include <conio.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include "tge.h"
  15. #include "tgefont.h"
  16. #include "tgemouse.h"
  17. #include "vcoord.h"
  18.  
  19. //*** #defines
  20. #define DRIVERNAME    "320X240.DRV"
  21. #define FONTNAME          "8X16.FNT"
  22.  
  23. //*** Function prototypes
  24. void setup(void);
  25. void demo(void);
  26.  
  27. //*** Global data
  28. Font font(FONTNAME);
  29. VirtualCoord virtScreen;
  30. int mouseExists;
  31.  
  32.  
  33. //*****
  34. //***** Program start
  35. //*****
  36.  
  37. void main(void)
  38. {
  39.   //*** Set things up
  40.   setup();
  41.  
  42.   //*** Run the demo
  43.   demo();
  44.  
  45.   //*** Restore text mode and quit
  46.   deInitGraphics();
  47. }
  48.  
  49.  
  50. //*****
  51. //***** General setup
  52. //*****
  53.  
  54. void setup(void)
  55. {
  56.   //*** Ensure font loaded correctly
  57.   if (!font.status())
  58.   {
  59.     printf("Error loading %s -- aborting.\n\n", FONTNAME);
  60.     exit(1);
  61.   }
  62.  
  63.   //*** Load the driver
  64.   if (loadGraphDriver(DRIVERNAME) != TGE_SUCCESS)
  65.   {
  66.     printf("Error loading %s -- aborting.\n\n", DRIVERNAME);
  67.     exit(1);
  68.   }
  69.  
  70.   //*** Initialize graphics mode
  71.   if (!initGraphics())
  72.   {
  73.     printf("Unable to initialize graphics hardware -- aborting.\n\n");
  74.     exit(1);
  75.   }
  76.  
  77.   //*** Initialize the font colours
  78.   font.foreground(colourCloseToX(255,255,255,0));    // white foreground
  79.   font.background(colourCloseToX(  0,  0,  0,0));    // black background
  80.  
  81.   //*** Initialize virtual coordinate system
  82.   virtScreen.virtParams(1023, 767);
  83.   virtScreen.realParams(OUTMAXX, OUTMAXY);
  84.  
  85.   //*** Set up the mouse
  86.   if ((mouseExists=resetMouse()) != 0)        // is mouse available?
  87.   {
  88.     initNewMouse();                // yes, initialize it
  89.     setHorizLimitsMouse(0, OUTMAXX);
  90.     setVertLimitsMouse(0, OUTMAXY);
  91.     setPosMouse(OUTMAXX/2, OUTMAXY/2);
  92.     setupMousePointer(BIG_ARROW_POINTER);
  93.     atexit(deInitNewMouse);
  94.   }
  95. }
  96.  
  97.  
  98. //*****
  99. //***** Silly little demo function
  100. //*****
  101.  
  102. void demo(void)
  103. {
  104.   unsigned blue;
  105.  
  106.   //*** Use colourCloseTo()
  107.   blue = colourCloseTo(0, 0, 200);
  108.  
  109.   //*** Use the virtual coordinate system
  110.   ellipse(MAXX/2, MAXY/2, virtScreen.realX(340), virtScreen.realY(170), blue);
  111.  
  112.   //*** Use the Font class
  113.   font.put(0, 0, "Press a key to quit...");
  114.  
  115.   //*** Use the mouse
  116.   if (mouseExists)
  117.     showMouse();
  118.  
  119.   //*** Get a key, then return
  120.   getch();
  121. }